package com.demo.List.ArrayList.pokerCard;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author :蕉绿
 * @Date : 2023/2/4 9:09
 * @Version : V1.0
 * @Description :
 */
class Card {
    public String num;
    public String suit;
    public String poker;

    public Card(String poker) {
        this.poker = poker;
    }

    public Card() {

    }
    public Card(String num, String suit) {
        this.num = num;
        this.suit = suit;
    }

    @Override
    public String toString() {
        if(poker == null)
        return suit + " " + num ;
        else
            return poker;
    }
}
public class CardDemo{
    public static final String[] suits = {"♠","♥","♣","♦"};
    public static final String[] nums = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
    public List<Card> buyCards() {
        List<Card> cards = new ArrayList<>();
        for (int i = 0; i < 13; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(nums[i],suits[j]);
                cards.add(card);
            }
        }
        Card poker1 = new Card("小王");
        Card poker2 = new Card("大王");
        cards.add(poker1);
        cards.add(poker2);
        return cards;

    }
    public List<Card> shuffle(List<Card> cards) {
        Random random = new Random();
        for (int i = cards.size() - 1; i > 0 ; i--) {

            int index = random.nextInt(i);
            swap(cards,index,i);
        }
        return cards;
    }
    private void swap(List<Card> cards,int i,int j) {
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }

}

